package cn.yi.boot.mq.config;

import cn.yi.boot.mq.rocketmq.message.handler.MessageHandler;
import cn.yi.boot.mq.rocketmq.yml.YmlTopic2MessageHandlerFactoryBean;
import org.springframework.beans.factory.config.YamlMapFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.util.List;

@Configuration
public class MessageHandlerFactoryConfig {


    @Bean
    public YmlTopic2MessageHandlerFactoryBean messageHandlerFactoryBean(List<MessageHandler> messageHandlers){
        YmlTopic2MessageHandlerFactoryBean messageHandlerFactoryBean = new YmlTopic2MessageHandlerFactoryBean();
        messageHandlerFactoryBean.setMessageHandlers(messageHandlers);
        YamlMapFactoryBean yamlMapFactoryBean =new YamlMapFactoryBean();
        yamlMapFactoryBean.setResources(new ClassPathResource("config/topic2TagHandler.yml"));
        messageHandlerFactoryBean.setYmlMap(yamlMapFactoryBean.getObject());
        return messageHandlerFactoryBean;
    }
}
